#include <wx/richtext/richtextstyles.h>
#include "wxsrichtextstylelistbox.h"

namespace {
  wxsRegisterItem<wxsRichTextStyleListBox> Reg( _T( "RichTextStyleListBox" ), _T( "富文本样式列表框" ), wxsTWidget, _T( "标准" ), 155 );
  WXS_ST_BEGIN( wxsRichTextStyleListBoxStyles, _T( "" ) )
  WXS_ST_CATEGORY( "wxRichTextStyleListBox" )
  WXS_ST_DEFAULTS()
  WXS_ST_END()
}

wxsRichTextStyleListBox::wxsRichTextStyleListBox( wxsItemResData* Data ):
  wxsWidget( Data, &Reg.Info, NULL, wxsRichTextStyleListBoxStyles ),
  m_sControl( wxEmptyString ),
  m_sStyleSheet( wxEmptyString ),
  m_iStyleType( wxRichTextStyleListBox::wxRICHTEXT_STYLE_PARAGRAPH ),
  m_bApplyOnSelection( false ) {}


void wxsRichTextStyleListBox::OnBuildCreatingCode() {
  switch( GetLanguage() ) {
  case wxsCPP: {
    AddHeader( _T( "<wx/richtext/richtextstyles.h>" ), GetInfo().ClassName, hfInPCH );
    Codef( _T( "%C(%W, %I, %P, %S, %T);\n" ) );
    wxString sVarName = GetVarName();
    if( !m_sControl.IsEmpty() ) {
      AddEventCode( wxString::Format( _T( "// Set the wxRichtTextCtrl for %s. \n" ), sVarName.wx_str() ) );
      AddEventCode( wxString::Format( _T( "%s->SetRichTextCtrl(%s);\n" ), sVarName.wx_str(), m_sControl.wx_str() ) );
    }
    if( !m_sStyleSheet.IsEmpty() ) {
      AddEventCode( wxString::Format( _T( "// Set the wxRichTextStyleSheet for %s. \n" ), sVarName.wx_str() ) );
      AddEventCode( wxString::Format( _T( "%s->SetStyleSheet(%s);\n" ), sVarName.wx_str(), m_sStyleSheet.wx_str() ) );
      AddEventCode( wxString::Format( _T( "%s->UpdateStyles();\n" ), sVarName.wx_str() ) );
    }
    switch( m_iStyleType ) {
    case wxRichTextStyleListBox::wxRICHTEXT_STYLE_ALL:
      Codef( _T( "%ASetStyleType(%s);\n" ), _T( "wxRichTextStyleListBox::wxRICHTEXT_STYLE_ALL" ) );
      break;
    case wxRichTextStyleListBox::wxRICHTEXT_STYLE_CHARACTER:
      Codef( _T( "%ASetStyleType(%s);\n" ), _T( "wxRichTextStyleListBox::wxRICHTEXT_STYLE_CHARACTER" ) );
      break;
    case wxRichTextStyleListBox::wxRICHTEXT_STYLE_LIST:
      Codef( _T( "%ASetStyleType(%s);\n" ), _T( "wxRichTextStyleListBox::wxRICHTEXT_STYLE_LIST" ) );
      break;
    default:
      break;
    }
    if( m_bApplyOnSelection ) {
      Codef( _T( "%ASetApplyOnSelection(%b);\n" ), m_bApplyOnSelection );
    }
    BuildSetupWindowCode();
    return;
  }
  case wxsUnknownLanguage:
  default: {
    wxsCodeMarks::Unknown( _T( "wxsRichTextStyleListBox::OnBuildCreatingCode" ), GetLanguage() );
  }
  }
}


wxObject* wxsRichTextStyleListBox::OnBuildPreview( wxWindow* Parent, long Flags ) {
  wxRichTextStyleListBox *Preview = new wxRichTextStyleListBox( Parent, GetId(), Pos( Parent ), Size( Parent ), Style() );
  switch( m_iStyleType ) {
  case wxRichTextStyleListBox::wxRICHTEXT_STYLE_ALL:
    Preview->SetStyleType( wxRichTextStyleListBox::wxRICHTEXT_STYLE_ALL );
    break;
  case wxRichTextStyleListBox::wxRICHTEXT_STYLE_CHARACTER:
    Preview->SetStyleType( wxRichTextStyleListBox::wxRICHTEXT_STYLE_CHARACTER );
    break;
  case wxRichTextStyleListBox::wxRICHTEXT_STYLE_LIST:
    Preview->SetStyleType( wxRichTextStyleListBox::wxRICHTEXT_STYLE_LIST );
    break;
  default:
    break;
  }
  if( m_bApplyOnSelection ) {
    Preview->SetApplyOnSelection( m_bApplyOnSelection );
  }
  return SetupWindow( Preview, Flags );
}


void wxsRichTextStyleListBox::OnEnumWidgetProperties( M_Code_unused long Flags ) {
  static const long StyleStates[] = {wxRichTextStyleListBox::wxRICHTEXT_STYLE_ALL,
                                     wxRichTextStyleListBox::wxRICHTEXT_STYLE_CHARACTER,
                                     wxRichTextStyleListBox::wxRICHTEXT_STYLE_LIST,
                                     wxRichTextStyleListBox::wxRICHTEXT_STYLE_PARAGRAPH
                                    };
  static const wxChar* StyleNames[]  = {_T( "wxRICHTEXT_STYLE_ALL" ), _T( "wxRICHTEXT_STYLE_CHARACTER" ), _T( "wxRICHTEXT_STYLE_LIST" ), _T( "wxRICHTEXT_STYLE_PARAGRAPH" ), NULL};
  WXS_SHORT_STRING( wxsRichTextStyleListBox, m_sControl, _T( "Control" ), _T( "control" ), wxEmptyString, true )
  WXS_SHORT_STRING( wxsRichTextStyleListBox, m_sStyleSheet, _T( "Style Sheet" ), _T( "style_sheet" ), wxEmptyString, true )
  WXS_ENUM( wxsRichTextStyleListBox, m_iStyleType, _T( "Style Type" ), _T( "style_type" ), StyleStates, StyleNames, wxRichTextStyleListBox::wxRICHTEXT_STYLE_PARAGRAPH )
  WXS_BOOL( wxsRichTextStyleListBox, m_bApplyOnSelection, _T( "Apply On Selection" ), _T( "apply_on_selection" ), false );
}
